/*
package com.sunqizhong.filter;

import com.sunqizhong.exception.BusinessException;
import com.sunqizhong.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
*/
/*@WebFilter("/*")*//*

public class LoginCheckFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //0、强转对象
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        //1、获取请求url
        StringBuffer url = req.getRequestURL();
        String uri = req.getRequestURI();
        log.info("url={}",url);  //eg:http://localhost:8080/login
        log.info("uri={}",uri);  //eg:login
        //2、判断请求url是否包含login，如果包含，说明是登录操作，放行
        if (uri.contains("login")){
            chain.doFilter(request,response);
            //[注意]：一定要结束当前请求，不应该继续往下执行代码逻辑
            return;
        }
        //3、获取请求头中的令牌（token）
        String token = req.getHeader("token");
        //4、判断令牌是否存在，如果不存在，响应401
        if (token == null){
            resp.setStatus(401);
            //throw new BusinessException("未登录，请先登录！");
            return;
        }
        //5、解析token，如果解析失败，响应401
        try {
            Claims claims = JwtUtils.parseJwt(token);
            log.info("claims={}",claims);
        } catch (Exception e) {
            resp.setStatus(401);
            log.error("令牌解析失败:{}",e.getMessage());
            //throw new BusinessException("未登录，请先登录");
            return;
        }
        //6、放行
        chain.doFilter(request,response);
    }
}
*/
